home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00019_Script_Texto Scroll < prev    next >
Text File  |  1999-03-19  |  7KB  |  245 lines

  1. property spr -- Sprite com botao de scroll, que contem behavior
  2. property sprTexto, memTexto -- sprite/membro do texto
  3. property yMin, yMax -- Posicoes minimas e maximas do indicador
  4. property tempoScroll
  5. property alturaLinha
  6. property extras
  7. property sprDesliga
  8.  
  9. -- Palavras selecionadas (clicadas)
  10. property linhasTela, linhasTexto
  11. property posicao, posicaoMax
  12. property ativo
  13.  
  14. -- Descricao da Behavior
  15. on getBehaviorDescription
  16.   return "Gerencia barra de scroll de texto: behavior deve ser" &¼
  17.          "colocado no indicador da barra de scroll"
  18. end
  19.  
  20. on getPropertyDescriptionList
  21.   set p_list = [ ¼
  22.      #sprTexto: [ #comment:   "Sprite que contem texto", ¼
  23.                     #format:   #integer, ¼
  24.                     #default:    1 ], ¼
  25.      #memTexto: [ #comment:   "Membro que contem texto", ¼
  26.                     #format:   #string, ¼
  27.                     #default:    "" ],¼
  28.      #yMin: [ #comment: "Posicao mais alta do indicador de scroll:",¼
  29.                     #format:   #integer,¼
  30.                     #default:  0],¼
  31.      #yMax: [ #comment: "Posicao mais alta do indicador de scroll:",¼
  32.                     #format:   #integer,¼
  33.                     #default:  240],¼
  34.      #ativo: [ #comment: "Inicia ativo (0/1):",¼
  35.                     #format:    #integer,¼
  36.                     #default:   1],¼
  37.   #tempoScroll: [ #comment: "Tempo entre cada linha scrollada:",¼
  38.                     #format:   #integer,¼
  39.                     #default:  0],¼
  40.   #extras: [ #comment: "Extras (1 p/ Scroll do historico):",¼
  41.                     #format:   #integer,¼
  42.                     #default:  0],¼
  43.   #sprDesliga: [ #comment: "Sprites p/ desligar caso nao precise de scroll:",¼
  44.                     #format:   #list,¼
  45.                     #default:  []]¼
  46.   ]
  47.   return p_list
  48. end
  49.  
  50. on beginSprite me
  51.   set spr = the spriteNum of me
  52.   if ativo = 0 then 
  53.     desativa me
  54.   else
  55.     inicializaSprite me
  56.   end if
  57. end
  58.  
  59. on desativa me
  60.   set ativo = false
  61.   set the visibility of sprite spr to false
  62. end
  63.  
  64.  
  65. -- Inicializacao do sprite
  66. on inicializaSprite me
  67.   set linhasTexto = the lineCount of member memTexto
  68.   set alturaLinha = the lineHeight of member memTexto
  69.   
  70.   
  71.   set linhasTela = the height of sprite sprTexto / alturaLinha
  72.   set posicao = 0
  73.   if linhasTexto <= linhasTela then
  74.     -- Se tem menos texto que o espaco na tela
  75.     -- nao precisa de scroll
  76.     set ativo = false
  77.     set the visibility of sprite spr to false
  78.     repeat with i = 1 to count(sprDesliga)
  79.       set the visibility of sprite getAt(sprDesliga,i) to false
  80.     end repeat
  81.     if extras = 1 then
  82.       puppetSprite 38,true
  83.       set the member of sprite 38 to¼
  84.          member (1 + the number of member "ScrollHistorico")
  85.     end if
  86.   else
  87.     set ativo = true
  88.     set the visibility of sprite spr to true
  89.     if extras = 1 then
  90.       puppetSprite 38,true
  91.       set the member of sprite 38 to¼
  92.          member "ScrollHistorico"
  93.     end if
  94.     set posicaoMax = linhasTexto - linhasTela / 2
  95.     indicador me, 0
  96.     set posicao = 0
  97.     set the scrollTop of member memTexto to 0
  98.   end if
  99.   
  100. end
  101.  
  102. -- Acerta posicao do indicador
  103. on indicador me, linha
  104.   set y = linha * (yMax - yMin) / posicaoMax + yMin
  105.   set the locV of sprite spr to y
  106. end
  107.  
  108. -- Mensagens de scroll
  109. on scrollingCima me
  110.   if not ativo then return
  111.   
  112.   global gCritico
  113.   set gCritico = gCritico + 1
  114.   
  115.   set ultimo = the timer - tempoScroll
  116.   repeat while the mouseDown
  117.     if posicao > 0 and (the timer - ultimo) > tempoScroll then 
  118.       -- scrollByLine member memTexto, -1
  119.       set posicao = posicao - 1
  120.       set the scrollTop of member memTexto to ¼
  121.           alturaLinha * posicao
  122.       indicador me, posicao
  123.       set ultimo = the timer
  124.       updateStage
  125.     end if
  126.     sendAllSprites(#idleSprite)
  127.   end repeat
  128.   
  129.   set gCritico = gCritico - 1
  130. end 
  131.  
  132. on scrollingBaixo me
  133.   if not ativo then return
  134.   
  135.   global gCritico
  136.   set gCritico = gCritico + 1
  137.   
  138.   set ultimo = the timer - tempoScroll
  139.   repeat while the mouseDown
  140.     if posicao < posicaoMax and (the timer - ultimo) > tempoScroll then 
  141.       -- scrollByLine member memTexto, +1
  142.       set posicao = posicao + 1
  143.       set the scrollTop of member memTexto to ¼
  144.           alturaLinha * posicao
  145.       indicador me, posicao
  146.       set ultimo = the timer
  147.       updateStage
  148.     end if
  149.     sendAllSprites(#idleSprite)
  150.   end repeat
  151.   
  152.   set gCritico = gCritico - 1
  153. end
  154.  
  155. on scrollPaginaCima me
  156.   if not ativo then return
  157.   
  158.   if posicao <= 0 then return
  159.   
  160.   set tmp = linhasTela
  161.   if tmp > posicao then set tmp = posicao
  162.   --  scrollByLine member memTexto, -tmp
  163.   set posicao = posicao - tmp
  164.   set the scrollTop of member memTexto to ¼
  165.           alturaLinha * posicao
  166.   indicador me,posicao
  167.   updateStage
  168. end
  169.  
  170. on scrollPaginaBaixo me
  171.   if not ativo then return
  172.   
  173.   if posicao >= posicaoMax then return
  174.   
  175.   set tmp = linhasTela
  176.   if tmp > posicaoMax - posicao then set tmp = posicaoMax - posicao
  177.   --  scrollByLine member memTexto, tmp
  178.   set posicao = posicao + tmp
  179.   set the scrollTop of member memTexto to ¼
  180.           alturaLinha * posicao
  181.   indicador me,posicao
  182.   updateStage
  183. end  
  184.  
  185. on clickBarra me
  186.   if not ativo then return
  187.   
  188.   global gCritico
  189.   set gCritico = gCritico + 1
  190.   
  191.   if the mouseV > the locV of sprite spr then
  192.     
  193.     scrollPaginaBaixo me
  194.     
  195.     set ultimo = the timer + tempoScroll 
  196.     repeat while the mouseDown
  197.       if the timer - ultimo > tempoScroll then
  198.         set ultimo = the timer
  199.         scrollPaginaBaixo me
  200.       end if
  201.       
  202.       sendAllSprites(#idleSprite)
  203.     end repeat
  204.     
  205.   else
  206.     scrollPaginaCima me
  207.     
  208.     set ultimo = the timer + tempoScroll
  209.     repeat while the mouseDown
  210.       if the timer - ultimo > tempoScroll then
  211.         set ultimo = the timer
  212.         scrollPaginaCima me
  213.       end if
  214.       
  215.       sendAllSprites(#idleSprite)
  216.     end repeat
  217.   end if
  218.   
  219.   set gCritico = gCritico - 1
  220. end
  221.  
  222. on mouseDown me
  223.   if not ativo then return
  224.   
  225.   -- Arraste
  226.   set posM = the mouseV
  227.   set difV = posM - the locV of sprite spr
  228.   
  229.   repeat while the mouseDown
  230.     if the mouseV <> posM then
  231.       set posM = the mouseV
  232.       set tmp = posM
  233.       if tmp < yMin then set tmp = yMin
  234.       else if tmp > yMax then set tmp = yMax
  235.       set tmp = posicaoMax*(tmp-yMin)/(yMax-yMin)
  236.       set the scrollTop of member memTexto to ¼
  237.           alturaLinha * tmp
  238.       -- scrollByLine member memTexto, tmp - posicao
  239.       set posicao = tmp
  240.       indicador me, posicao
  241.       updateStage
  242.     end if
  243.   end repeat
  244.   
  245. end